package edu.dev.tfile.common;

import com.alibaba.fastjson.JSON;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;

public class Utils {

	public static final String BASE_PATH = System.getProperty("user.dir");

	private static final Properties configPro = new Properties();

	static {
		try {
			configPro.load(new FileInputStream(BASE_PATH + "/conf/config.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getConfig(String key) {
		return configPro.getProperty(key);
	}

	public static String getJSON(Object object) {
		return JSON.toJSONString(object);
	}
	
	public static void sendMsg(HttpServletResponse resp, String msg) {
		try {
			resp.setContentType("text/html;charset=utf-8");
			resp.setStatus(HttpServletResponse.SC_OK);
			resp.getWriter().println(msg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
